Add click-to-focus: clicking notification brings Windows Terminal to foreground#6
Conversation
…foreground Replace Start-Sleep with a WinForms message loop so BalloonTipClicked can be handled. On click, ShowWindow (SW_RESTORE) + SetForegroundWindow focus the Windows Terminal window immediately.
There was a problem hiding this comment.
Pull request overview
This PR enhances the Windows notification system for Claude Code on WSL2 by adding click-to-focus functionality. When a user clicks the balloon notification, Windows Terminal is automatically restored and brought to the foreground, eliminating the need to manually switch windows.
Changes:
- Replaced sleep-based timing with a WinForms message loop to enable event handling
- Added Win32 API functions (
SetForegroundWindow,ShowWindow) for window manipulation - Implemented
BalloonTipClickedandBalloonTipClosedevent handlers to focus Windows Terminal and exit gracefully - Updated documentation to reflect the new architecture and added troubleshooting guidance for click-to-focus issues
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| \$notification.add_BalloonTipClicked({ | ||
| \$wt = Get-Process -Name 'WindowsTerminal' -ErrorAction SilentlyContinue | Select-Object -First 1 | ||
| if (\$wt -and \$wt.MainWindowHandle -ne [IntPtr]::Zero) { | ||
| [Win32]::ShowWindow(\$wt.MainWindowHandle, 9) | Out-Null |
There was a problem hiding this comment.
The magic number 9 should be documented or replaced with a named constant for clarity. In Win32 API, 9 corresponds to SW_RESTORE, which restores a minimized window. Consider adding a comment explaining this value, such as: [Win32]::ShowWindow(\$wt.MainWindowHandle, 9) | Out-Null # SW_RESTORE
| [Win32]::ShowWindow(\$wt.MainWindowHandle, 9) | Out-Null | |
| [Win32]::ShowWindow(\$wt.MainWindowHandle, 9) | Out-Null # SW_RESTORE |
Summary
Start-Sleep -Seconds 6with a WinForms message loop (Application.Run()) so click events can be handledSetForegroundWindowandShowWindow(SW_RESTORE) to the Win32 P/Invoke classBalloonTipClickedhandler restores Windows Terminal (if minimised) and brings it to the foregroundBalloonTipClosedhandler exits the loop cleanly on timeout or dismissTest plan
PermissionRequest(e.g. run a command that needs approval) and alt-tab away